package com.study.StringExample;

import java.util.Arrays;

public class StringTest {
    public static void main(String[] args) {
        String s="abcd";
        /*s=s.concat("ef");
        System.out.println(s);*/
        String b="abcd";
        System.out.println(s.hashCode()+";;;;"+b.hashCode());
        if(s==b){
            System.out.println("s==b");
        }else{
            System.out.println("s!=b");
        }
        /**equals()方法、hashCode()方法的区别*/
        if(s.equals(b)){
            System.out.println("s  equals b");
        }else{
            System.out.println("s  !equals b");
        }

        /**利用substring分解字符串*/
        System.out.println(s.substring(1));
        System.out.println(s.substring(3,4));


        /**String 不可变*/
        /**（1）final类 和 final的私有成员*/
        /**（2）改变即创建对象的方法*/
        char[] arr = new char[]{'a','b','c','d'};
        String str = new String(arr);
        arr[3]='e';
        System.out.println("str= "+str);
        System.out.println("arr[]= "+Arrays.toString(arr));

        String s1 = "Love You";
        String s2 = "Love"+" You";
        String s3 = s2 + "";
        String s4 = new String("Love You");
        System.out.println("s1 == s2 "+(s1==s2));
        System.out.println("s1 == s3 "+(s1==s3));
        System.out.println("s1 == s4 "+(s1==s4));
        System.out.println("s3 == s4 "+(s3==s4));

        System.out.println("s3 equals s4 "+(s3.equals(s4)));

        /**位移运算*/
        int i=3;
        System.out.println(31*i);
        System.out.println(((i<<5)-i));
        System.out.println((3<<1));
        System.out.println((3<<5));
        System.out.println((2<<2));
        System.out.println((2>>1));

        /**replaceFirst、replaceAll、replace 区别*/
        /**replace 没有用到正则表达式*/
        /**replaceAll 和replaceFirst用到正则表达式*/
        String st = "my.test.txt";
        System.out.println(st.replace(".", "#"));
        System.out.println(st.replaceAll("\\.", "#"));
        System.out.println(st.replaceFirst("\\.", "#"));

       /* String string = "";
        for(int m=0;i<10000;m++){
            string += "hello";
        }*/

       /***** stringBuilder ***/
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("hello").append("world!");
        System.out.println(stringBuilder.toString());

        /**会被jvm优化*/
        String str1 = "I";
        str1 += "love"+"java";
        System.out.println(str1);

        String aa=null;
        System.out.println(aa.concat("a"));
    }
}
